package com.woniuxy.controllers;

import com.github.pagehelper.PageInfo;
import com.woniuxy.entitys.Associate;
import com.woniuxy.entitys.Client;
import com.woniuxy.entitys.RestPOJO;
import com.woniuxy.services.AssociateService;
import com.woniuxy.services.ClientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "客户交往记录管理接口")
public class AssociateController {
    @Autowired
    private AssociateService associateService;

    @ApiOperation(
            value = "根据查询条件查询交往记录",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="selMsg",value="查询条件",required=false),
            @ApiImplicitParam(paramType="query",name="comid",value="公司的id",required=true),
            @ApiImplicitParam(paramType="query",name="currentPage",value="当前页",required=true),
            @ApiImplicitParam(paramType="query",name="pageSize",value="每页显示的条目数",required=true),
    })


    @GetMapping("/associate")
    public RestPOJO getAssByComId(String selMsg,String comid, Integer currentPage, Integer pageSize){
        System.out.println("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
        RestPOJO restPOJO = new RestPOJO();
        PageInfo<Associate> pageInfo = associateService.getAssByComId(selMsg,comid,currentPage,pageSize);
        if(pageInfo != null && pageInfo.getList().size() > 0){
            restPOJO.setMessage("成功");
            restPOJO.setStatus(200);
            restPOJO.setData(pageInfo);
        }else {
            restPOJO.setMessage("失败");
            restPOJO.setStatus(250);
            restPOJO.setData(pageInfo);
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "删除交往记录（更改交往记录表status值为0）",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @PostMapping("/associatedel")
    public RestPOJO delAss(@RequestBody Associate associate){
        RestPOJO restPOJO = new RestPOJO();
        Integer res = associateService.delAss(associate);
        if(res > 0){
            restPOJO.setMessage("成功");
            restPOJO.setStatus(200);
        }else {
            restPOJO.setMessage("失败");
            restPOJO.setStatus(250);
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "添加交往记录",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @PostMapping("/associateAdd")
    public RestPOJO addAss(@RequestBody Associate associate){
        RestPOJO restPOJO = new RestPOJO();
        Integer res = associateService.addAss(associate);
        if(res > 0){
            restPOJO.setMessage("成功");
            restPOJO.setStatus(200);
        }else {
            restPOJO.setMessage("失败");
            restPOJO.setStatus(250);
        }
        return restPOJO;
    }
}
